import path from "path";
import { toolchain } from "../toolchain.js";
import { YamlModifier } from "../tools/YamlModifier.js";

const test = () => {
    const ym = new YamlModifier(path.join(toolchain.option.projectRoot!, 'ProjectSettings/ProjectSettings.asset'), { indent: '  ' });
    const btdtcf = ym.modifier.getNodeOrThrow('PlayerSettings').getNodeOrThrow('m_BuildTargetDefaultTextureCompressionFormat');
    const nodes = btdtcf.getArraySubNodes();
    let contains = false;
    for (const node of nodes) {
        if (node.getNodeOrThrow('m_BuildTarget').getValue() == 'WebGL') {
            contains = true;
            node.getNodeOrThrow('m_Format').setValue('456');
            console.log(node.getNodeOrThrow('m_Format').getValue());
        }
    }
    
    if (!contains) {
        btdtcf.addArraySubNode({
            m_BuildTarget: 'WebGL',
            m_Format: '3'	
        });
    }
    // 下述fileID为单行，暂不支持
    //console.log(ym.modifier.getNodeOrThrow('PlayerSettings').getNodeOrThrow('switchIcons_0').getNodeOrThrow('fileID').getValue());
    ym.save();
}

test();
